<extend name="Public/base" />
<block name="main">
    <fieldset class="layui-elem-field">
        <legend>短信管理 - 余额充值</legend>
        <div class="layui-field-box">
            <form class="layui-form" action="">
                <if condition="isset($detail['id'])">
                    <input type="hidden" name="id" value="{$detail['id']}">
                </if>
                <div class="layui-form-item">
                    <input type="hidden" value="{$detail['c_id']}" name="c_id">
                    <label class="layui-form-label">商户名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" required value="{$detail['company_name']}" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">可分配余额</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <input  value="{$sms_num}" readonly class="layui-input">
                    </div>
                    <input type="hidden" id="sms_num" name="sms_num" value="{$sms_num}">
                    <div class="layui-form-mid layui-word-aux">平台可分配条数，不允许修改</div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">充值量</label>
                    <div class="layui-input-block">
                        <input type="text" name="recharge_num" id="recharge_num"  lay-verify="required" placeholder="请输入充值短信条数" class="layui-input" style="width: 300px;"><span id="prompt"></span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </fieldset>
</block>
<block name="myScript">

        <input type="hidden" name="id" value="{$detail['id']}">
        <script>
            layui.use('form', function(){
                var form = layui.form();
                form.on('submit(formDemo)', function(data){
                    $.ajax({
                        type: "POST",
                        url: '{:U("recharge")}',
                        data: data.field,
                        success: function(msg){
                            if( msg.code == 1 ){
                                parent.location.reload();
                            }else{
                                parent.layer.msg(msg.msg, {
                                    icon: 5,
                                    shade: [0.6, '#393D49'],
                                    time:1500
                                });
                            }
                        }
                    });
                    return false;
                });

            });
            $(function(){
                $("#recharge_num").blur(function () {
                    var recharge_num = $(this).val();
                    var sms_num=$('#sms_num').val();
                    if (parseInt(recharge_num)>parseInt(sms_num)) {
                        $("#prompt").html("短信充值条数不得大于平台可分配余额");
                        return false;
                    }else{
                        $("#prompt").html(" ");
                        return true;
                    }
                })
            })
        </script>

    <style type="text/css">
        span {color: #ff6b77}
    </style>

</block>